#PM2.5 leaflets
PM25_1990_leaflet
PM25_2017_leaflet
DALY_1990_leaflet
DALY_2017_leaflet
DALY_change_leaflet
tempdata <- data_healthimp_wide[, c(1, 2, 3, 4, 5)]
tempdata <- tempdata%>%
pivot_wider(values_from = `ambientpm2.5.dalyper1k`,
names_from = sex,
names_glue = "{sex}")
tempdata$DALY <- tempdata$`F` + tempdata$M
tempdata <- tempdata%>%
select(-c(`F`, M))
tempdata <- tempdata[tempdata$year == 1990 | tempdata$year == 1995 | tempdata$year == 2000| tempdata$year == 2005| tempdata$year == 2010| tempdata$year == 2011| tempdata$year == 2012| tempdata$year == 2013| tempdata$year == 2014| tempdata$year == 2015| tempdata$year == 2016| tempdata$year == 2017, ]
path_bella <- "C:/Users/Bella/Desktop/git/Blog-HealthAndJusticeLeague/data"
data_PM25 <- read_csv(paste0(path_bella,
"/Exposure_PM25_air.csv"))
## Warning: 10 parsing failures.
## row col expected actual file
## 7627 Flag Codes 1/0/T/F/TRUE/FALSE E 'C:/Users/Bella/Desktop/git/Blog-HealthAndJusticeLeague/data/Exposure_PM25_air.csv'
## 7627 Flags 1/0/T/F/TRUE/FALSE Estimated value 'C:/Users/Bella/Desktop/git/Blog-HealthAndJusticeLeague/data/Exposure_PM25_air.csv'
## 7628 Flag Codes 1/0/T/F/TRUE/FALSE E 'C:/Users/Bella/Desktop/git/Blog-HealthAndJusticeLeague/data/Exposure_PM25_air.csv'
## 7628 Flags 1/0/T/F/TRUE/FALSE Estimated value 'C:/Users/Bella/Desktop/git/Blog-HealthAndJusticeLeague/data/Exposure_PM25_air.csv'
## 10263 Flag Codes 1/0/T/F/TRUE/FALSE E 'C:/Users/Bella/Desktop/git/Blog-HealthAndJusticeLeague/data/Exposure_PM25_air.csv'
## ..... .......... .................. ............... ...................................................................................
## See problems(...) for more details.
#taking out unnecessary column varaibles
data_PM25 <- data_PM25%>%
select(COU, Country, Variable, Year, Value)%>%
rename(country = Country,
year = Year)
#separate out the variables
data_PM25_wide <- data_PM25%>%
pivot_wider(values_from = Value,
names_from = Variable,
names_glue = "{Variable}")
tempdata2 <- left_join(tempdata, data_PM25_wide, by = c("country", "year"), copy = TRUE)%>%
select(-c(COU, cou))
tempdata3 <- tempdata2[, -c(5, 6, 7, 8)]
tempdata3 <- tempdata3%>%
pivot_longer(-c(year, country),
names_to = "measure_type", values_to = "value")
ggplot(data = tempdata3, mapping = aes(x = year, y = value, color = as.factor(measure_type))) +
geom_point() +
labs(
title = "TITLE",
subtitle = "1990 to 2017",
y = "Value",
x = "Year")
## Warning: Removed 216 rows containing missing values (geom_point).

#trying out sth different in the meantime
library(ggplot2)
library(gganimate)
library(gifski)
tempdata <- data_healthimp_wide[, c(1, 2, 3, 4, 5)]
tempdata <- tempdata%>%
pivot_wider(values_from = `ambientpm2.5.dalyper1k`,
names_from = sex,
names_glue = "{sex}")
tempdata$DALY <- tempdata$`F` + tempdata$M
tempdata <- tempdata%>%
select(-c(`F`, M))
tempdata <- tempdata[tempdata$year == 1990 | tempdata$year == 1995 | tempdata$year == 2000| tempdata$year == 2005| tempdata$year == 2010| tempdata$year == 2011| tempdata$year == 2012| tempdata$year == 2013| tempdata$year == 2014| tempdata$year == 2015| tempdata$year == 2016| tempdata$year == 2017, ]
path_bella <- "C:/Users/Bella/Desktop/git/Blog-HealthAndJusticeLeague/data"
data_PM25 <- read_csv(paste0(path_bella,
"/Exposure_PM25_air.csv"))
#taking out unnecessary column varaibles
data_PM25 <- data_PM25%>%
select(COU, Country, Variable, Year, Value)%>%
rename(country = Country,
year = Year)
#separate out the variables
data_PM25_wide <- data_PM25%>%
pivot_wider(values_from = Value,
names_from = Variable,
names_glue = "{Variable}")
tempdata2 <- left_join(tempdata, data_PM25_wide, by = c("country", "year"), copy = TRUE)%>%
select(-c(COU, cou))
g <- ggplot(tempdata2, aes(`Mean population exposure to PM2.5`, DALY, color = country))+
geom_point(alpha = 0.7, show.legend = FALSE)+
scale_size(range = c(2, 12))+
scale_x_continuous(trans = 'log10')+
scale_y_continuous(trans = 'log10')+
labs(title = 'Year: {frame_time}', x = 'PM 2.5', y = 'DALY per 1K')+
transition_time(year)+
ease_aes('linear')
animate(g, duration = 10, fps = 20, width = 400, height = 400, renderer = gifski_renderer())

anim_save("tempdata2.gif")